package org.rkuk.kasutil.test.util 
{
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import org.rkuk.kasutil.test.event.AnsyTimeoutEvent;
	
	/**
	 * ...
	 * @author rkuk
	 */
	public class AnsyEventTimer extends EventDispatcher 
	{
		private var timer_:Timer;
		private var eventTarget_:EventDispatcher;
		private var eventType_:String;
		
		public function AnsyEventTimer(delay:Number,eventTarget:EventDispatcher,eventType:String) 
		{
			super();
			timer_ = new Timer(delay, 1);
			eventTarget_ = eventTarget;
			eventType_ = eventType;
		}
		
		public function start():void
		{
			timer_.addEventListener(TimerEvent.TIMER, onTimerEvent);
			timer_.start();
		}
		
		public function stop():void
		{
			timer_.removeEventListener(TimerEvent.TIMER, onTimerEvent);
			timer_.stop();
		}
		
		private function onTimerEvent(e:TimerEvent):void 
		{
			timer_.removeEventListener(TimerEvent.TIMER, onTimerEvent);
			dispatchEvent(new AnsyTimeoutEvent(eventTarget_, eventType_, timer_.delay));
		}
	}
}